<?php // Article ?>
<?php
	$sql = "select a.moduleheading 
			from ms_module a 
			where 	a.stsrc = 'A' 
				and a.modulename = '".$doc_name."' 
				and a.moduleid = '".$doc_id."' 
				and a.modulestatus = 1 
			limit 0,1
			";
	
	$exe = mysql_query($sql) or die(mysql_error());
	$num = mysql_num_rows($exe);
	$row = mysql_fetch_array($exe);
?>
<div>
	<h2><?php if($num > 0){ echo $row['moduleheading']; } ?></h2>
</div>
<div>
<?php // Get Title(Label), Single Text, View Single Text, title alias

	$uri = $_SERVER['REQUEST_URI'];
	$uri_var = explode('/', $uri);
	
	$count = count($uri_var);
	if(substr($uri,-1,1) == "/")
	{
		$count = $count-2;
	}
	else
	{
		$count = $count-1;
	}
	
	for( $i = 0; $i <= $count; $i++ )
	{
		$var_name[] = "uri_" . $i;
	}
	
	for( $i = 0; $i < $count+1; $i++ )
	{
		${$var_name[$i]}  = $uri_var[$i];
	}

	$string_1 = "";
	$string_2 = "";
	
	if(isset($uri_1)){$string_1 = $uri_1;}
	if(isset($uri_2)){$string_2 = $uri_2;}
	
	if(strtolower($string_1) == "article")
	{
		if($string_2 != "" || !empty($string_2))	// Display Article Detail
		{
			$sql = "select a.*, c.filename 
					from tbl_text a 
						left join ms_module b 
							on a.moduleid = b.moduleid and b.stsrc = 'A' 
						left join ms_file c
							on a.texturlimage = c.fileid and c.stsrc = 'A' and c.filerole = 'image' 
					where 	a.stsrc = 'A' 
						and b.modulename = '".$string_1."' 
						and b.moduleid = '".$doc_id."' 
						and a.textstatus = 1 
						and a.textname = '".$string_2."'
					order by a.textposition asc 
					limit 0,1
					";
					//echo $sql;die();
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			$row = mysql_fetch_array($exe);
			
			if($num > 0)
			{
?>
	
	<h3><?php echo stripslashes(html_entity_decode($row['textlabel'])); ?></h3>
	<p style="text-align:right;"><?php if(!empty($row['dateup']) || $row['dateup'] != "" || $row['dateup'] != null){echo "<i>Last updated</i> ".date('d M Y, H:i', strtotime(stripslashes(html_entity_decode($row['dateup']))));}else{echo date('d M Y, H:i', strtotime(stripslashes(html_entity_decode($row['datein']))));} ?></p>
	<p>
		<?php
			if($row['texturlimagestatus'] == 1)
			{
		?>
		<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="float:right; max-width:300px; max-height:300px; padding:0 0 10px 5px;" />
		<?php
			}
		?>
		<?php echo stripslashes(html_entity_decode($row['textheader'])); ?>
		<?php echo stripslashes(html_entity_decode($row['textcontent'])); ?>
		<div class="clear"></div>
	</p>

<?php
			}
		}
		else	// Display all Article List
		{
			$sql = "select a.*, c.filename
					from tbl_text a 
						left join ms_module b 
							on 		a.moduleid = b.moduleid 
								and b.stsrc = 'A' 
						left join ms_file c
							on		a.texturlimage = c.fileid
								and c.stsrc = 'A'
					where 	a.stsrc = 'A' 
						and b.modulename = '".$doc_name."' 
						and b.moduleid = '".$doc_id."' 
						and a.textstatus = 1 
					order by a.dateup asc, b.datein asc 
					limit 0,10
					";
			$exe = mysql_query($sql) or die(mysql_error());
			$num = mysql_num_rows($exe);
			
			
			if($num > 0)
			{
?>
	<div>
		<table cellpadding="0" cellspacing="0" border="0">
<?php
				while($row = mysql_fetch_array($exe))
				{
?>
					<tr>
						<td style="vertical-align:top; text-align:center; padding-top:10px;">
							<?php
								if($row['texturlimagestatus'] == 1)
								{
							?>
							<a href="<?php echo getURLdomain(); ?>/article/<?php echo stripslashes(html_entity_decode($row['textname'])); ?>" >
								<img src="<?php echo getURLdomain()."/upload/".$row['filename']; ?>" style="max-width:300px; max-height:300px;" />
							</a>
							<?php
								}
							?>
						</td>
						<td style="vertical-align:top;">
							<div style="padding:10px;">
								<a style="font-weight:bold; font-size:18px; color:#E36C0A;" href="<?php echo getURLdomain(); ?>/article/<?php echo stripslashes(html_entity_decode($row['textname'])); ?>" >
									<?php echo stripslashes(html_entity_decode($row['textlabel'])); ?>
								</a>
								<?php if($row['textheader'] != "") { ?>
								<br />
								<br />
								<?php 
									$text = htmlentities($row['textheader']);
									$set = 300; // how many character will be displayed
									
									echo preg_replace('/\s+?(\S+)?$/', '', substr($text, 0, $set)); // substring text until last defined words
									
									if(strlen($text) > $set || $row['textcontent'] != "") { echo " ..."; }
								?>
								<?php } ?>
								<br />
								<br />
								<a href="<?php echo getURLdomain(); ?>/article/<?php echo stripslashes(html_entity_decode($row['textname'])); ?>" >
									Baca Selengkapnya ...
								</a>
							</div>
						</td>
					</tr>
<?php
				}
?>
		</table>
	</div>
<?php
			}
		}
	}
?>
</div>